package com.mall.web.controller.mall;

import com.mall.common.core.controller.BaseController;
import com.mall.common.core.page.TableDataInfo;
import com.mall.product.domain.biz.ProProductBiz;
import com.mall.product.domain.entity.ProProduct;
import com.mall.product.service.ProProductService;
import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

@Controller
@RequestMapping("/mall/product")
public class MallProductController
    extends BaseController {

  private String prefix = "mall/product";

  @Autowired
  private ProProductService proProductService;

  @GetMapping("/list.html")
  public String list(ModelMap mmap) {
//    mmap.put("products", proProductService.selectProductAll());
    return prefix + "/list";
  }

  @GetMapping("/detail/{productId}")
  public String list(@PathVariable("productId") Long productId, ModelMap mmap) {

    ProProductBiz proProduct = proProductService.selectProProductById(productId);
    mmap.put("product", proProduct);
    return prefix + "/detail";
  }

  /**
   * 查询商品列表
   */
  @PostMapping("/list")
  @ResponseBody
  public TableDataInfo list(ProProduct proProduct) {

    startPage();
    List<ProProductBiz> list = proProductService.selectProProductList(proProduct);
    return getDataTable(list);
  }

}
